package com.sdy.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;

/**
mysql> desc modelinfo;
+---------------+--------------+------+-----+---------+----------------+
| Field         | Type         | Null | Key | Default | Extra          |
+---------------+--------------+------+-----+---------+----------------+
| id            | int(11)      | NO   | PRI | NULL    | auto_increment |
| dataType      | varchar(32)  | YES  |     | NULL    |                |
| textValue     | text         | YES  |     | NULL    |                |
| index         | varchar(32)  | YES  |     | NULL    |                |
| modelId       | int(11)      | YES  |     | NULL    |                |
| downloadTimes | int(11)      | YES  |     | NULL    |                |
| watchTimes    | int(11)      | YES  |     | NULL    |                |
| picUrl        | varchar(100) | YES  |     | NULL    |                |
| imageText     | blob         | YES  |     | NULL    |                |
+---------------+--------------+------+-----+---------+----------------+
 * */
public class Modeinfo extends Model<Modeinfo> {

	private static final long serialVersionUID = -6262421333245545781L;
	
	public static final Modeinfo dao = new Modeinfo();
	
	public void batchSaveMode(List<Modeinfo> modes){
		for (Modeinfo modeinfo : modes) {
			modeinfo.save();
		}
	}
	
	public void batchDeleteMode(int modelId){
		Db.update("delete from modelinfo where modelId = ?", modelId);
	}
	
	public List<Modeinfo> findMode(int modelId){
		List<Modeinfo> modes = find("select * from modelinfo where modelId = ?", modelId);
		return modes;
	}
	
	public void batchDeleteModeByOwner(String owner) throws Exception {
		Db.update("delete from modelinfo where owner = ?", owner);
	}

}
